export async function getToken(request: Request) {
  const cookieHeader = request.headers.get('Cookie');
  if (!cookieHeader) return null;

  const cookies = cookieHeader.split(';').reduce((acc, cookie) => {
    const [key, value] = cookie.trim().split('=');
    acc[key] = value;
    return acc;
  }, {} as Record<string, string>);

  const authStorage = cookies['auth-storage'];
  if (!authStorage) return null;

  try {
    const { state } = JSON.parse(decodeURIComponent(authStorage));
    return state.token;
  } catch {
    return null;
  }
}